/**
 * 
 */
package com.wskj.library.book.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wskj.library.pojo.BorrowInfo;
import com.wskj.library.service.BookService;
import com.wskj.library.service.impl.BookServiceImpl;
import com.wskj.util.Page;
import com.wskj.util.StringUtil;

/**
 * @author 胡洋
 * @describe 
 * @Date 2018年3月27日上午10:52:59
 * @version 1.0
 */
@WebServlet(urlPatterns="/book/borrow/list.do")
public class BorrowListServlet extends HttpServlet {
	BookService bookService=new BookServiceImpl();
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取用户输入的参数 
		String bname=StringUtil.nullToString(req.getParameter("bname"));
		String rname=StringUtil.nullToString(req.getParameter("rname"));
		
		// 借出时间 .....  不早于这个时间....
		Date borrowTime=StringUtil.nullToDate(req.getParameter("borrowTime"));
		
		//默认是第一页 
		int index=StringUtil.nullToInt(req.getParameter("pageIndex"));
		
		Page<BorrowInfo> page=new Page<>(index, 10);
		
		
		// 查询   满足条件的 总条数  。。。
		long  counts=bookService.getBorrowsCounts(bname,rname,borrowTime);
		page.setCounts(counts);
		
		List<BorrowInfo> borrows=bookService.getBorrowsWithPage(bname,rname,borrowTime,index,page.getPageSize());
		//分页的数据 ...		
		page.setData(borrows);		
		req.setAttribute("page",page);	
		req.getRequestDispatcher("/WEB-INF/page/borrow/list.jsp").forward(req, resp);
	}

}
